package router

import (
	"github.com/gin-gonic/gin"
	"hotel-app/client/client"
	"hotel-app/client/request"
	"hotel-app/common/proto/hotel"
)

func SendSms(c *gin.Context) {
	var data request.SendSms
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	sms, err := client.SendSms(c, &hotel.SendSmsReq{
		Mobile: data.Mobile,
		Source: data.Source,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": sms,
	})
}
func UserLogin(c *gin.Context) {
	var data request.UserLogin
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	login, err := client.UserLogin(c, &hotel.UserLoginReq{
		Mobile: data.Mobile,
		Code:   data.Code,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": login,
	})
}
func OrderList(c *gin.Context) {
	list, err := client.OrderList(c, &hotel.OrderListReq{})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": list,
	})
}
func OrderListByUser(c *gin.Context) {
	userId := 1
	list, err := client.OrderListByUser(c, &hotel.OrderListByUserReq{UserId: int64(userId)})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": list,
	})
}
